package org.neptune.service.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.neptune.api.entity.SeckillUser;
import org.neptune.api.entity.SeckillUserExample;
import org.neptune.service.dao.SeckillUserMapper;
import org.neptune.service.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lwl
 * @date 2019/8/23 18:00
 */
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private SeckillUserMapper seckillUserMapper;

	@Override
	public SeckillUser queryUserByUserName(String username) {

		SeckillUserExample example = new SeckillUserExample();
		if (StringUtils.isNotBlank(username)) {
			example.createCriteria().andUsernameEqualTo(username);
			List<SeckillUser> seckillUsers = seckillUserMapper.selectByExample(example);
			if (CollectionUtils.isNotEmpty(seckillUsers)) {
				return seckillUsers.get(0);
			}
		}
		return null;
	}
}
